<?php

namespace App\Http\Controllers\Home;

use App\Http\Models\Article;
use App\Http\Models\Category;
use App\Http\Models\Links;
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\DB;


class IndexController extends CommonController
{
    //前台首页
    public function index()
    {


        $data = Article::join('category','article.cate_id','=','category.cate_id')->orderBy('art_order','asc')->take(5)->get();
        // 友情链接
        $link = Links::orderBy('link_order','asc')->take(5)->get();

        return view('home.index',compact('nav','hot','data','news','link'));
    }
    // 分类展示
    public function cate($cate_id)
    {
        // 查看次数每次加一个
        Category::where('cate_id',$cate_id)->increment('cate_view',1);
        $data = Article::where('cate_id',$cate_id)->paginate(4);
        $data->_cate = Category::find($cate_id);
        $rnav = Category::where('cate_pid',$cate_id)->get();

        return view('home.list',compact('data','rnav'));

    }
    // 文章详情页
    public function show($art_id)
    {
        // 查看次数每次加一个
        Article::where('art_id',$art_id)->increment('art_view',1);
        // 文章详情
        $field = Article::join('category','article.cate_id','=','category.cate_id')->where('art_id',$art_id)->first();
        // 上一篇
        $field->art_prev = Article::where('art_id','<',$art_id)->orderBy('art_id','desc')->first();
        // 下一篇
        $field->art_next = Article::where('art_id','>',$art_id)->orderBy('art_id','asc')->first();
        // 相关文章6篇
        $about = Article::where('cate_id',$field->cate_id)->take(6)->get(['art_id','art_title']);
        return view('home.new',compact('field','about'));
    }

}
